<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:body>
	<ui:composition template="/pages/protected/prof/template.xhtml">
		<ui:define name='templatemo_content'>
			<script>
				resposta = '#{quest.respostaText}';
			</script>
			<h:outputScript library='scripts' name='camporesposta.js' />
			<!-- Cabeçalho  -->
			<h2>
				Questões
				<h:form id="btnNovo">
					<p:commandButton value="Novo" icon="ui-icon-check"
							update=":questForm :listaQuestao" async="true"  ajax="true"
							action="#{questaoMB.doPrepararInserir()}" oncomplete="dlg.show();  campoResposta('');">
						</p:commandButton>
				</h:form>
			</h2>

			<!-- Lista de Questões -->
			<h:form id="listaQuestao">
				<p:dataTable id="tbQuestoes" widgetVar="tbQuestoes" var="quest"
					value="#{questaoMB.questoes}" paginator="true" rows="10"
					paginatorPosition="bottom"
					paginatorTemplate="{PageLinks} {RowsPerPageDropdown}"
					rowsPerPageTemplate="5,10,15"
					emptyMessage="Nenhuma Questao foi encontrada.">

					<p:column headerText="Enunciado" filterBy="#{quest.enunciadoText}"
						filterMatchMode="contains">
						<h:outputText value="#{quest.enunciadoText}" />
					</p:column>

					<p:column headerText="Nível" filterBy="#{quest.nivelDificuldade}"
						filterMatchMode="contains">
						<h:outputText value="#{quest.nivelDificuldade}" />
					</p:column>

					<p:column headerText="Temas" filterBy="#{quest.temas}"
						filterMatchMode="contains">
						<h:outputText value="#{quest.temas}" />
					</p:column>

					<!-- Botoes de Acoes -->
					<p:column style="width:4%">
						<p:commandButton id="btnEditar" icon="ui-icon-pencil"
							oncomplete="dlg.show(); campoResposta('#{quest.respostaText}');" update=":questForm">
							<f:setPropertyActionListener value="#{quest}"
								target="#{questaoMB.qst}" />
						</p:commandButton>
						<p:tooltip for="btnEditar" value="Editar" showEffect="fade"
							hideEffect="fade" />
					
						<p:commandButton id="btnDeletar" icon="ui-icon-trash"
							title="Selecionar cliente" action="#{questaoMB.doRemover(quest)}"
							update=":listaQuestao">
						</p:commandButton>
						<p:tooltip for="btnDeletar" value="Deletar" showEffect="fade"
							hideEffect="fade" />
					</p:column>
				</p:dataTable>
			</h:form>

			<!-- Novo  -->
			<p:dialog id="Dialog" header="Questão" widgetVar="dlg"
				modal="true" height="450px" width="520px"  resizable="false">
				<p:outputPanel>
					<h:form id="questForm" prependId="false">
						<h:panelGrid id="Panel" columns="2" style="height:400px;">
							<h:outputLabel for="nShowEnunciadoImage" value=" " />
							<h:panelGrid columns="2" style="margin-left: 0px !important;">
								<h:selectBooleanCheckbox id="nShowEnunciadoImage"
									value="#{questaoMB.qst.enunciadoAsImage}" /> Mostrar imagem no enunciado
							</h:panelGrid>

							<h:outputLabel  value="" />
							<p:panelGrid columns="2" style="width:100%;">
								<p:graphicImage value="#{questaoMB.imagem}" id="imagem" cache="false" width="100px" height= "100px"/>
								<p:fileUpload style="display:inline-block; width:200px; max-width:200px;" sizeLimit="3145728" widgetVar="uploader" label="Escolher imagem..."  fileUploadListener="#{questaoMB.fileUpload}" auto="true" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"  update="imagem" multiple="false"  customUI="false">
								</p:fileUpload>
							</p:panelGrid>

							<h:outputLabel for="nEnunciado" value="Enunciado:" />
							<p:inputTextarea id="nEnunciado" rows="3" cols="54"
								value="#{questaoMB.qst.enunciadoText}" />

 
							<h:outputLabel for="questOpcoes" value="Opcoes:" />
							<p:inputTextarea id="questOpcoes" rows="3" cols="54"
								onblur="campoResposta(#{(questaoMB.qst.respostaText) ? questaoMB.qst.respostaText : ''});" value="#{questaoMB.qst.opcoes}">
							</p:inputTextarea>
								
							<h:outputLabel value="Resposta: *" />
							<p:outputPanel id="respostaContainer">
								
							</p:outputPanel>
							
							<h:outputLabel for="nNivel" value="Dificuldade: *" />
							<p:spinner id="nNivel"
								value="#{questaoMB.qst.nivelDificuldade}" required="true"
								label="Dificuldade" min="1">
							</p:spinner>

							<h:outputLabel for="nTemas" value="Temas:" />
							<p:inputTextarea id="nTemas" rows="3" cols="54"
								value="#{questaoMB.qst.temas}" />

						</h:panelGrid>
						
						<p:commandButton value="Salvar" icon="ui-icon-check"
							update=":questForm :listaQuestao" async="true"  ajax="true"
							action="#{questaoMB.doSalvar()}">
						</p:commandButton>
						<p:commandButton value="Cancelar" icon="ui-icon-closethick"
							immediate="true" update=":questForm :listaQuestao"
							process="@this" oncomplete="dlg.hide()" />
					</h:form>
				</p:outputPanel>
			</p:dialog>

		</ui:define>
	</ui:composition>

</h:body>
</html>
